<?php
    include_once("../action/checkAuthenticationAction.php");
    include_once("../service/bannerService.php");
    include_once("../util/constant.php");
    
    include_once("../util/authUtil.php");
    $perm_array = $_SESSION["permissions"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Dashboard</title>
	<?php include("import-css.php");?>	
</head>
<body>
	<?php include("header.php");?>
    
    <div class="container-fluid">
		<div class="row-fluid">
            <!--Menu-->
            <?php include("menu.php");?>
            <!--Content-->
            <div class="box span10 offset2">
    					<div class="box-header well" data-original-title>
                            <?php
                                if(!authUtil(array("edit banner","create banner","view banner","delete banner"),$perm_array,false)){
                                    echo "<script>window.location.href='../admin/index.php';</script>";
                                }
                            
                                $require_perm = array("create banner");
                                if(authUtil($require_perm,$perm_array,true)){
                            ?>
            						<a class="btn btn-primary" href="./banner_detail.php?action=<?php echo NEW_ACTION; ?>">
                                        <i class="icon-edit icon-white"></i>Thêm mới
                                    </a>
                            <?php
                                }
                            ?>
    						<div class="box-icon">
    							<a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a>
    							<a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
    						</div>
    					</div>
    					<div class="box-content">
    						<table class="table table-striped table-bordered bootstrap-datatable datatable">
    						  <thead>
    							  <tr>
    								  <th>Type</th>
    								  <th>Bài viết/Sự kiện</th>
    								  <th>Trạng thái</th>
                                      <th>Chức năng</th>
    							  </tr>
    						  </thead>   
    						  <tbody>
                                <?php
                                $banners = getAllBanner();
                                    while($banner = mysql_fetch_array($banners)){
                                ?>
                                        <tr>
                                            <td>
                                                <?php
                                                    $type = $banner["BANNER_TYPE"];
                                                    if($type == 1){
                                                        echo "Banner trái";
                                                    }else if($type == 2){
                                                        echo "Banner giữa";
                                                    }else if($type == 3){
                                                        echo "Banner phải";
                                                    }else{
                                                        echo "Banner sự kiện";
                                                    } 
                                                ?>
                                            </td>
                                            <td>
                                                <?php echo $banner["EVENT_TITLE"]; ?>
                                            </td>
                                            <td>
                                                <?php
                                                    echo $banner["BANNER_STATUS"]==1?"bật":"tắt";
                                                ?>
                                            </td>
                                            <td>    
                                            <?php
                                                $require_perm = array("edit banner","create banner");
                                                if(authUtil($require_perm,$perm_array,false)){
                                            ?>
                                                    <a class="btn btn-info" href="./banner_detail.php?action=<?php echo EDIT_ACTION; ?>&id=<?php echo $banner['BANNER_ID']; ?>">
        												<i class="icon-edit icon-white"></i>  
        												Cập nhật
        											</a>
                                            <?php
                                                }
                                            ?>
                                            <?php
                                                $require_perm = array("delete banner");
                                                if(authUtil($require_perm,$perm_array,true)){
                                                    if($banner["BANNER_STATUS"]!=1){
                                            ?>
            											<a class="btn btn-danger" href="../action/deleteBanner.php?id=<?php echo $banner['BANNER_ID']; ?>">
            												<i class="icon-trash icon-white"></i>
            												Xóa
            											</a>
                                            <?php
                                                    }
                                                }
                                            ?>
                                            </td>
                                        </tr>
                                <?php
                                    }
                                ?>
    						  </tbody>
    					  </table>            
                        </div>
            </div><!--/span-->
        </div>
    </div>

    <?php include("footer.php");?>
		
	</div><!--/.fluid-container-->

	<?php include("import-js.php");?>	
    
</body>
</html>
